package com.tz.hello;

import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017/1/6.
 */
@Component(value = "hello")
public class SimpleHello implements IHello {

    @Override
    public String sayHi(String name) {
        System.out.println("---- in method: before return ....");
        //模拟一个异常
        randomException();
        //
        System.out.println("无异常，将正常返回....");
        return "Hello,"+name;
    }

    //随机异常
    private void randomException() {
        int i = (int)(Math.random() *100) + 1;
        //
        if(i % 2 == 0) {
            throw new RuntimeException("自定义的异常....");
        }
    }
}
